using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nop.Core.Domain.Directory;
using Nop.Core.Infrastructure;

namespace Nop.Core.ApiDataModel
{
    public class Address
    {
        /// <summary>
        /// Gets or sets the address Id
        /// </summary>
        public int? Id { get; set; }

        /// <summary>
        /// Gets or sets the first name
        /// </summary>
        public string FirstName { get; set; }

        /// <summary>
        /// Gets or sets the last name
        /// </summary>
        public string LastName { get; set; }

        /// <summary>
        /// Gets or sets the email
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// Gets or sets the company
        /// </summary>
        public string Company { get; set; }

        /// <summary>
        /// Gets or sets the country identifier
        /// </summary>
        public int? CountryId { get; set; }

        /// <summary>
        /// country name
        /// </summary>
        public string CountryName { set; get; }

        /// <summary>
        /// Gets or sets the state/province identifier
        /// </summary>
        public int? StateProvinceId { get; set; }

        /// <summary>
        /// provincename
        /// </summary>
        public string StateProvinceName { set; get; }

        /// <summary>
        /// Gets or sets the city
        /// </summary>
        public string City { get; set; }

        /// <summary>
        /// Gets or sets the address 1
        /// </summary>
        public string Address1 { get; set; }

        /// <summary>
        /// Gets or sets the address 2
        /// </summary>
        public string Address2 { get; set; }

        /// <summary>
        /// Gets or sets the zip/postal code
        /// </summary>
        public string ZipPostalCode { get; set; }

        /// <summary>
        /// Gets or sets the phone number
        /// </summary>
        public string PhoneNumber { get; set; }

        /// <summary>
        /// Gets or sets the cellphone number
        /// </summary>
        public string CellPhoneNumber { get; set; }

        /// <summary>
        /// Gets or sets the fax number
        /// </summary>
        public string FaxNumber { get; set; }

        public Address()
        {
        }

        public Address(Nop.Core.Domain.Common.Address address)
        {
            this.Id = address.Id;
            this.FirstName = address.FirstName;
            this.LastName = address.LastName;
            this.Email = address.Email;
            this.Company = address.Company;
            this.CountryId = address.CountryId;
            this.StateProvinceId = address.StateProvinceId;
            this.City = address.City;
            this.Address1 = address.Address1;
            this.Address2 = address.Address2;
            this.ZipPostalCode = address.ZipPostalCode;
            this.PhoneNumber = address.PhoneNumber;
            this.CellPhoneNumber = address.CellPhoneNumber;
            this.FaxNumber = address.FaxNumber;

            if (CountryId != null)
            {
                this.CountryName = address.Country.Name;
            }
            if (StateProvinceId == null) return;
            this.StateProvinceName = address.StateProvince.Name;
        }

        public Nop.Core.Domain.Common.Address ToEntity()
        {
            Nop.Core.Domain.Common.Address destination = new Nop.Core.Domain.Common.Address();
            if (null != this.Id) destination.Id = this.Id.Value;
            destination.FirstName = this.FirstName;
            destination.LastName = this.LastName;
            destination.Email = this.Email;
            destination.Company = this.Company;
            destination.CountryId = this.CountryId;
            destination.StateProvinceId = this.StateProvinceId;
            destination.City = this.City;
            destination.Address1 = this.Address1;
            destination.Address2 = this.Address2;
            destination.ZipPostalCode = this.ZipPostalCode;
            destination.PhoneNumber = this.PhoneNumber;
            destination.CellPhoneNumber = this.CellPhoneNumber;
            destination.FaxNumber = this.FaxNumber;

            return destination;
        }

        public void UpdateEntity(Nop.Core.Domain.Common.Address destination)
        {
            if (null != this.Id) destination.Id = this.Id.Value;
            destination.FirstName = this.FirstName;
            destination.LastName = this.LastName;
            destination.Email = this.Email;
            destination.Company = this.Company;
            destination.CountryId = this.CountryId;
            destination.StateProvinceId = this.StateProvinceId;
            destination.City = this.City;
            destination.Address1 = this.Address1;
            destination.Address2 = this.Address2;
            destination.ZipPostalCode = this.ZipPostalCode;
            destination.PhoneNumber = this.PhoneNumber;
            destination.CellPhoneNumber = this.CellPhoneNumber;
            destination.FaxNumber = this.FaxNumber;
        }
    }
}
